package com.example.user_service.user_contorller.FDao;

import com.example.user_service.vo.UserDataVO;
import com.example.user_service.vo.UserVO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.Date;

/**
 * @author fcr
 * @date 2021-12-14 11:35
 **/

@Mapper
@Repository
public interface UserMapper {

    @Select("select * from user_login where user_id=#{user_id}")
    @Results(
            {
                    @Result(property = "user_id", column = "user_id"),
                    @Result(property = "tel", column = "tel"),
                    @Result(property = "account", column = "account"),
                    @Result(property = "email", column = "email"),
                    @Result(property = "paswd", column = "paswd"),
                    @Result(property = "user_type", column = "user_type"),
                    @Result(property = "idcard", column = "idcard"),
                    @Result(property = "login_time", column = "login_time"),
            }

    )
    UserVO selectmylogin(int user_id);


    @Select("select * from user_data where user_id=#{user_id}")
    @Results(
            {
                    @Result(property = "user_id", column = "user_id"),
                    @Result(property = "user_name", column = "user_name"),
                    @Result(property = "user_birthday", column = "user_birthday"),
                    @Result(property = "user_gender", column = "user_gender"),
                    @Result(property = "user_img", column = "user_img"),
                    @Result(property = "user_area", column = "user_area"),
                    @Result(property = "user_zsxm", column = "user_zsxm"),
                    @Result(property = "user_createtime", column = "user_createtime"),

            }

    )
    UserDataVO selectmydata(int user_id);


    @Update("UPDATE user_login SET account=#{account} WHERE user_id=#{user_id}")
    void changeaccount(String account,int user_id);

    @Update("UPDATE user_data SET user_zsxm=#{user_zsxm},user_birthday=#{user_birthday},user_gender=#{user_gender},user_area=#{user_area} WHERE user_id=#{user_id}")
    int datachange(String user_zsxm, Date user_birthday,int user_gender,String user_area,int user_id);

    @Update("UPDATE user_data SET user_img=#{user_img} WHERE user_id=#{user_id}")
    int changehead(String user_img,int user_id);

    @Update("UPDATE user_login SET paswd=#{paswd} WHERE user_id=#{userid}")
    int updatepwd(String paswd, int userid);

    @Update("UPDATE user_login SET paswd=#{paswd} WHERE tel=#{tel}")
    int forgetpwd(String paswd, String tel);

    @Update("UPDATE user_login SET email=#{email} WHERE user_id=#{userid}")
    int updateemail(int userid,String email);

    @Update("UPDATE user_login SET tel=#{tel} WHERE user_id=#{userid}")
    int updatephone(int userid, String tel);

    @Update("UPDATE user_login SET user_type=1 WHERE user_id=#{userid}")
    boolean updatetype(int userid);

    @Select("select * from user_login where user_id=#{user_id} and paswd=#{paswd}")
    @Results(
            {
                    @Result(property = "user_id", column = "user_id"),
                    @Result(property = "tel", column = "tel"),
                    @Result(property = "account", column = "account"),
                    @Result(property = "email", column = "email"),
                    @Result(property = "paswd", column = "paswd"),
                    @Result(property = "user_type", column = "user_type"),
                    @Result(property = "idcard", column = "idcard"),
                    @Result(property = "login_time", column = "login_time"),
            }

    )
    UserVO f_login(int user_id,String paswd);

    @Select("select * from user_login where user_id=#{user_id} and idcard=#{idcard}")
    @Results(
            {
                    @Result(property = "user_id", column = "user_id"),
                    @Result(property = "tel", column = "tel"),
                    @Result(property = "account", column = "account"),
                    @Result(property = "email", column = "email"),
                    @Result(property = "paswd", column = "paswd"),
                    @Result(property = "user_type", column = "user_type"),
                    @Result(property = "idcard", column = "idcard"),
                    @Result(property = "login_time", column = "login_time"),
            }

    )
    UserVO f_checkid(int user_id, String idcard);

    @Select("select * from user_login where email=#{email}")
    @Results(
            {
                    @Result(property = "user_id", column = "user_id"),
                    @Result(property = "tel", column = "tel"),
                    @Result(property = "account", column = "account"),
                    @Result(property = "email", column = "email"),
                    @Result(property = "paswd", column = "paswd"),
                    @Result(property = "user_type", column = "user_type"),
                    @Result(property = "idcard", column = "idcard"),
                    @Result(property = "login_time", column = "login_time"),
            }

    )
    UserVO f_checkemail( String email);

    @Select("select user_type from user_login where user_id=#{userid}")
    @Results(
            {
                    @Result(property = "user_type", column = "user_type"),
            }

    )
    int selectmytype(int userid);

}
